﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AconITF.Controls
{
	/// <summary>
	/// DigitalNum.xaml 的交互逻辑
	/// </summary>
	public partial class DigitalNum : UserControl
	{
		public DigitalNum()
		{
			InitializeComponent();
		}



		public string Title
		{
			get { return (string)GetValue(TitleProperty); }
			set { SetValue(TitleProperty, value); }
		}
		public static readonly DependencyProperty TitleProperty =
			DependencyProperty.Register("Title", typeof(string), typeof(DigitalNum), new PropertyMetadata("标题"));


		public string Unit
		{
			get { return (string)GetValue(UnitProperty); }
			set { SetValue(UnitProperty, value); }
		}
		public static readonly DependencyProperty UnitProperty =
			DependencyProperty.Register("Unit", typeof(string), typeof(DigitalNum), new PropertyMetadata("V"));


		public double DisplayValue
		{
			get { return (double)GetValue(DisplayValueProperty); }
			set { SetValue(DisplayValueProperty, value); }
		}

		public static readonly DependencyProperty DisplayValueProperty =
			DependencyProperty.Register("DisplayValue", typeof(double), typeof(DigitalNum), new PropertyMetadata(0d));

		public double DigitWidth
		{
			get { return (double)GetValue(DigitWidthProperty); }
			set { SetValue(DigitWidthProperty, value); }
		}
		public static readonly DependencyProperty DigitWidthProperty =
			DependencyProperty.Register("DigitWidth", typeof(double), typeof(DigitalNum), new PropertyMetadata(0d, OnDigitWidthChanged));

		private static void OnDigitWidthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as DigitalNum)?.UpdateDigitWidth();

		private void UpdateDigitWidth()
		{
			if (DigitWidth > 0)
			{
				DigitalTxt.Width = DigitWidth;
			}
			else
			{
				DigitalTxt.Width = double.NaN;
			}
		}
	}
}
